<template>
  <div class="mech-Container">
    <div class="head">
      <div class="opt">
        <router-link to="/addMech">
          <el-button type="primary">新增机构</el-button>
        </router-link>
      </div>
      <div class="search">
        <el-input
          placeholder="请输入项目名称"
          suffix-icon="el-icon-search"
          v-model="search"
          @keyup.enter.native="getsearchList()"
        ></el-input>
      </div>
    </div>

    <el-table :data="List" border style="width: 100%">
      <el-table-column prop="index" label="序号" width="120"></el-table-column>
      <el-table-column prop="mechanismName" label="机构名称"></el-table-column>
      <el-table-column prop="bankName" label="开户银行"></el-table-column>
      <el-table-column prop="cardNo" label="账号"></el-table-column>
      <el-table-column prop="name" label="法定代表人"></el-table-column>
      <el-table-column label="开户许可证">
        <template slot-scope="scope">
          <img :src="`http://mov.freebd.cn:808/file${scope.row.permission}`" style="height:50px">
        </template>
      </el-table-column>
      <el-table-column label="营业执照">
        <template slot-scope="scope">
          <img
            :src="`http://mov.freebd.cn:808/file${scope.row.businessLicence}`"
            style="height:50px"
          >
        </template>
      </el-table-column>
      <el-table-column label="法人身份证背面照">
        <template slot-scope="scope">
          <img :src="`http://mov.freebd.cn:808/file${scope.row.idback}`" style="height:50px">
        </template>
      </el-table-column>
      <el-table-column label="法人身份证正面照">
        <template slot-scope="scope">
          <img :src="`http://mov.freebd.cn:808/file${scope.row.idcard}`" style="height:50px">
        </template>
      </el-table-column>
      <el-table-column prop="phone" label="注册手机号" width="120px"></el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <!-- 待审核   审核通过   审核不通过 -->
          <!-- 认证状态（0:未审核，1审核中，2审核通过，3审核失败） -->
          <el-button type="text" v-show="scope.row.certStatus == 0">未审核</el-button>
          <el-button type="text" v-show="scope.row.certStatus == 1">审核中</el-button>
          <el-button type="text" v-show="scope.row.certStatus == 2">审核通过</el-button>
          <el-button type="text" v-show="scope.row.certStatus == 3">审核失败</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="money" label="账户余额"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleClick(scope.row)"
            v-show="scope.row.certStatus == 0"
          >审核</el-button>
          <!-- <el-button type="text" disabled v-show="scope.row.certStatus !== 0">无操作</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <div class="paginat">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage4"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      search: "",
      List: [],
      val: 1,
      total: 0,
      currentPage4: 1
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //审核
    handleClick(row) {
      this.$confirm("是否进行机构审核？", "审核", {
        distinguishCancelAndClose: true,
        confirmButtonText: "通过",
        cancelButtonText: "不通过"
      })
        .then(() => {
          let url = "/user/update";
          let params = {
            certStatus: 2,
            uId: row.uId,
            checksId: row.checksId
          };
          this.httpPost(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "通过"
              });
              this.getList();
            } else {
              this.$message({
                type: "warning",
                message: res.message
              });
            }
          });
        })
        .catch(action => {
          if (action === "cancel") {
            let url = "/user/update";
            let params = {
              certStatus: 3,
              uId: row.uId,
              checksId: row.checksId
            };
            this.httpPost(url, params, res => {
              if (res.code == 200) {
                this.$message({
                  type: "info",
                  message: "不通过"
                });
                this.getList();
              } else {
                this.$message({
                  type: "warning",
                  message: res.message
                });
              }
            });
          }
        });
    },
    //分页
    handleCurrentChange(val) {
      this.val = val;
      this.getList();
      console.log(`当前页: ${val}`);
    },
    //搜索数据
    getsearchList() {
      let url = "/user/getusers";
      let params = {
        mechanismName: this.search, //机构名称
        pageNum: this.val,
        pageSize: 10
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.List = res.data.list;
          this.total = res.data.total;
          this.val = this.val == "" ? 1 : this.val;
          this.List.forEach((element, i) => {
            this.List[i].index = (this.val - 1) * 10 + i + 1;
          });
        }
      });
    },
    //获取数据
    getList() {
      let url = "/user/getusers";
      let params = {
        // mechanismName: this.search, //机构名称
        pageNum: this.val,
        pageSize: 10
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.List = res.data.list;
          this.total = res.data.total;
          this.val = this.val == "" ? 1 : this.val;
          this.List.forEach((element, i) => {
            this.List[i].index = (this.val - 1) * 10 + i + 1;
          });
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.head {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .search {
    width: 300px;
  }
}
</style>

<style lang="scss">
.mech-Container {
  .el-button + .el-button {
    margin-left: 0px !important;
  }
}
</style>